#!/usr/bin/env python

import RPi.GPIO as GPIO
from time import sleep
import datetime
import array
touchOut = 18
touchPin = 18

#remove '0x' and convert to int
def addZero(s):
	s = s[2:]
	length = len(s)
	while length<4:
		s = '0'+s
		length = length + 1
	return s 

def convertToBit(s):
	#print(s)
	temp = s[2:]
	#print(temp)
	#print type(temp)
	first = bin(int(temp[0],16))
	second = bin(int(temp[1],16))
	first = addZero(first)
	second = addZero(second)
	
	return first + second

def xor(check,bin8):
	i = 0
	res = ''
	while i<8:
		if check[i] == bin8[i]:
			#print 'same'
			res = res + '1'
		else:
			res = res + '0'
		i = i + 1
	#print 'res' + res
	return res


#checkValue
def checkValue(s):
	h = array.array('b',s)
	check = convertToBit(hex(h[0]))
	
	for i in range(1,len(h)):
		
		bin8 = convertToBit(hex(h[i]))
		#print bin8
		check = xor(check,bin8)
		#print 'che'+check
		
	#print hex(int(check,2))[2:]
	return hex(int(check,2))[2:]



#g = "011752.00,A,3407.52406500,N,10849.89752857,E,0.012,107.3,151221,3.3,W,A,474"
g = "20211216022608016,20211216022608016" #
res = checkValue(g)
print res


